package httpclient

import (
	"os"

	"github.com/spf13/viper"
)

type GetGatewayConfig struct {
	AccessToken string
	DeviceId    string
}

func ApiGetGatewayConfig(req GetGatewayConfig) ([]byte, error) {
	TpHost := os.Getenv("TP_HOST")
	if TpHost == "" {
		TpHost = viper.GetString("thingspanel.address")
	}
	response, err := PostJson("http://"+TpHost+"/api/plugin/device/config", req)
	return response, err
}

type GetAllGatewayConfigReq struct {
	ProtocolType string `json:"protocol_type"`
	DeviceType   string `json:"device_type"`
}

func ApiGetAllGatewayConfig(req GetAllGatewayConfigReq) ([]byte, error) {
	TpHost := os.Getenv("TP_HOST")
	if TpHost == "" {
		TpHost = viper.GetString("thingspanel.address")
	}
	response, err := PostJson("http://"+TpHost+"/api/plugin/all_device/config", req)
	return response, err
}
